#include "jinbuguo.h"

#include <httpclient.h>
#include <qrcutil.h>

JinBuGuo::JinBuGuo()
{

}

QString JinBuGuo::name()
{
    return "金步国作品集";
}

QString JinBuGuo::prefix()
{
    return "http://www.jinbuguo.com";
}

QStringList JinBuGuo::searching(const QString &text)
{
    QStringList list;

    foreach (auto line, QR("://jinboguo.txt").split("\n", Qt::SkipEmptyParts)) {
        auto var = line.split("\t").at(0);
        auto html = line.split("\t").at(1);
        auto title = html.mid(html.indexOf("<title>")+7);
        title = title.mid(0, title.indexOf("</title>"));
        if (text.isEmpty()) {
            list << title;
        } else {
            if (title.contains(text, Qt::CaseInsensitive)) {
                list << title;
            }
        }
    }

    return list;
}

QString JinBuGuo::content(const QString &text)
{
    foreach (auto line, QR("://jinboguo.txt").split("\n", Qt::SkipEmptyParts)) {
        auto var = line.split("\t").at(0);
        auto html = line.split("\t").at(1);
        auto title = html.mid(html.indexOf("<title>")+7);
        title = title.mid(0, title.indexOf("</title>"));
        if (text.compare(title) == 0) {
            return var;
        }
    }
    return "";
}
